# -*- coding: utf-8 -*-

from odoo import models, fields, api
from odoo.exceptions import ValidationError


# class openacademy(models.Model):
#     _name = 'openacademy.openacademy'
#
#     name = fields.Char(required=True)


class Course(models.Model):
    _name = 'openacademy.course'
    _description = "OpenAcademy Courses"

    name = fields.Char(string="名字", required=True)
    description = fields.Text()
    start_date = fields.Date()
    duration = fields.Float(digits=(6, 2), help="Duration in days")
    seats = fields.Integer(string="Number of seats")
    color = fields.Integer()
    # taken_seats = fields.Float(string="Taken seats", compute='_taken_seats')

    amount = fields.Integer(string="Number of amount")
    unit_price = fields.Integer()
    price = fields.Integer()
    age = fields.Integer()

    # @api.constrains('age')
    # def _check_something(self):
    #     for record in self:
    #         if record.age > 20:
    #             raise ValidationError("Your record is too old: %s" % record.age)
    #
    # @api.onchange('amount', 'unit_price')
    # def _onchange_price(self):
    #     # set auto-changing field
    #     self.price = self.amount * self.unit_price
    #     # Can optionally return a warning and domains
    #     if self.amount>100:
    #         return {
    #             'warning': {
    #                 'title': "Something bad happened",
    #                 'message': "amount的数量太大",
    #             }
    #         }
    #
    # @api.depends('taken_seats')
    # def _taken_seats(self):
    #     self.taken_seats=40.0
